package com.dq.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.http.HttpStatus;

import java.util.List;

/**
 * @author cf
 * 返回列表
 * @param <T>
 */
@Data
@ApiModel(value = "列表返回")
public class ListDataVo<T> extends Vo {
    private ReturnData data;

    @Data
    private static class ReturnData <T> {
        /**
         * 当前页数量
         */
        @ApiModelProperty(value = "返回数据量")
        private long currentPageTotal;
        /**
         * 数据总量
         */
        @ApiModelProperty(value = "返回数据总量")
        private long total;

        /**
         * 统计使用
         */
        @ApiModelProperty(value = "返回总值")
        private Object totalNum;

        /**
         * 列表数据
         */
        @ApiModelProperty(value = "数据内容")
        private List<T> list;
    }

    public ListDataVo(List<T> list) {
        super(HttpStatus.OK);

        ReturnData<T> returnData = new ReturnData<>();
        returnData.setList(list);
        returnData.setCurrentPageTotal(list.isEmpty() ? 0 : list.size());

        this.setData(returnData);
    }

    /**
     * 分页使用
     */
    public ListDataVo(List<T> list, long total) {
        super(HttpStatus.OK);

        ReturnData<T> returnData = new ReturnData<>();
        returnData.setList(list);
        returnData.setCurrentPageTotal(list.isEmpty() ? 0 : list.size());
        returnData.setTotal(total);

        this.setData(returnData);
    }

    public ListDataVo(List<T> list, long total, Object totalNum) {
        super(HttpStatus.OK);

        ReturnData<T> returnData = new ReturnData<>();
        returnData.setList(list);
        returnData.setCurrentPageTotal(list.isEmpty() ? 0 : list.size());
        returnData.setTotal(total);
        returnData.setTotalNum(totalNum);

        this.setData(returnData);
    }

}
